package com.nullpointer.xchatfinal.object;

import java.util.Collection;
import java.util.Date;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class MessageContent {
	public enum MsgType {
		TEXT, IMAGE, UPDATE_INFO, SEND_TYPING, SEND_STOP_TYPING, 
		SEND_CHAT_VIDEO_REQUEST, SAY_HI_REQUEST, ONLINE, OFFLINE, 
		SAY_HI_REQUEST_LV2, SEND_VOICE_CHAT, SEND_VOICE_CALL_REQUEST, 
		CHECK_FRIEND_ONLINE, CHECK_USER_ONLINE, FRIEND_ONLINE, 
		USER_ONLINE, ADD_GROUP, UPDATE_GROUP_INFO, ACCEPT_VIDEO_CALL, 
		REJECT_VIDEO_CALL, RECEIVE_CHAT_VIDEO_REQUEST, MESSAGE_STATE_DILIVER
	}

	private Long messageID;
	private Integer fromUserID; // from me? or from other user, a member of
								// group or member of chat(sender)
	private String name;
	private String content;
	private MsgType msgType;
	private String avatarID;
	private MessageState messageState = MessageState.SENDING;

	public MessageContent() {
		super();
	}

	public MessageState getMessageState() {
		return messageState;
	}

	public MessageContent(Integer fromUserID) {
		super();
		this.fromUserID = fromUserID;
		this.messageID = new Date().getTime() + fromUserID;
	}

	public void setMessageState(MessageState messageState) {
		this.messageState = messageState;
	}

	public String getAvatarID() {
		return avatarID;
	}

	public Long getMessageID() {
		return messageID;
	}

	public void setMessageID(Long messageID) {
		this.messageID = messageID;
	}

	public void setAvatarID(String avatarID) {
		this.avatarID = avatarID;
	}

	public Integer getFromUserID() {
		return fromUserID;
	}

	public void setFromUserID(Integer fromUserID) {
		this.fromUserID = fromUserID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public MsgType getMsgType() {
		return msgType;
	}

	public void setMsgType(MsgType msgType) {
		this.msgType = msgType;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static MessageContent fromJsonToMessageContent(String json) {
		try {
			MessageContent messageContent = new JSONDeserializer<MessageContent>()
					.use(null, MessageContent.class).deserialize(json);
			return messageContent;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String toJsonArray(Collection<MessageContent> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

}
